<!DOCTYPE html>


  <html class="dark page-post">


<head><meta name="generator" content="Hexo 3.9.0">
  <meta charset="utf-8">
  
  <title>webpack常用插件总结篇 | Poetry&#39;s Blog</title>

  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">

  
    <meta name="keywords" content="优化,webpack,">
  

  <meta name="description" content="一、功能类1.1 html-webpack-plugin 自动生成html，基本用法：  new HtmlWebpackPlugin(&amp;#123;  filename: &apos;index.html&apos;, // 生成文件名  template: path.join(process.cwd(), &apos;./index.html&apos;) // 模班文件&amp;#125;) 1.2 copy-webpack-plugin 拷">
<meta name="keywords" content="优化,webpack">
<meta property="og:type" content="article">
<meta property="og:title" content="webpack常用插件总结篇">
<meta property="og:url" content="http://blog.poetries.top/2018/11/20/webpack-config-optize/index.html">
<meta property="og:site_name" content="Poetry&#39;s Blog">
<meta property="og:description" content="一、功能类1.1 html-webpack-plugin 自动生成html，基本用法：  new HtmlWebpackPlugin(&amp;#123;  filename: &apos;index.html&apos;, // 生成文件名  template: path.join(process.cwd(), &apos;./index.html&apos;) // 模班文件&amp;#125;) 1.2 copy-webpack-plugin 拷">
<meta property="og:locale" content="zh-Hans">
<meta property="og:image" content="https://segmentfault.com/img/remote/1460000016816816?w=400&h=421">
<meta property="og:updated_time" content="2020-08-15T04:25:31.942Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="webpack常用插件总结篇">
<meta name="twitter:description" content="一、功能类1.1 html-webpack-plugin 自动生成html，基本用法：  new HtmlWebpackPlugin(&amp;#123;  filename: &apos;index.html&apos;, // 生成文件名  template: path.join(process.cwd(), &apos;./index.html&apos;) // 模班文件&amp;#125;) 1.2 copy-webpack-plugin 拷">
<meta name="twitter:image" content="https://segmentfault.com/img/remote/1460000016816816?w=400&h=421">

  

  
    <link rel="icon" href="/favicon.ico">
  

  <link href="/css/styles.css?v=c114cbeddx" rel="stylesheet">
<link href="/css/other.css?v=c114cbeddx" rel="stylesheet">


  
    <link rel="stylesheet" href="/css/personal-style.css">
  

  

  
  <script type="text/javascript">
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "//hm.baidu.com/hm.js?40b1f89aa80f2527b3db779c6898c879";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>


  
  <script type="text/javascript">
	(function(){
	    var bp = document.createElement('script');
	    var curProtocol = window.location.protocol.split(':')[0];
	    if (curProtocol === 'https') {
	        bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';        
	    }
	    else {
	        bp.src = 'http://push.zhanzhang.baidu.com/push.js';
	    }
	    var s = document.getElementsByTagName("script")[0];
	    s.parentNode.insertBefore(bp, s);
	})();
  </script>



  
    <script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
    <link rel="stylesheet" href="//cdn.bootcss.com/font-awesome/4.3.0/css/font-awesome.min.css">
  

  <!-- 聊天系统 -->
  
    
   <link type="text/css" rel="stylesheet" href="/renxi/default.css">
   <style>
      #modal {
        position: static !important;
      }
      .filter {
        width: 100%;
        height: 100%;
        position: absolute;
        top: 0;
        left: 0;
        background: #fe5757;
        animation: colorChange 30s ease-in-out infinite;
        animation-fill-mode: both;
        mix-blend-mode: overlay;
      }
  
      @keyframes colorChange {
        0%, 100% {
            opacity: 0;
        }
        50% {
            opacity: .9;
        }
      }
   </style>
</head>
</html>
<body>
  
  
    <span id="toolbox-mobile" class="toolbox-mobile">导航</span>
  

  <div class="post-header CENTER">
   
  <div class="toolbox">
    <a class="toolbox-entry" href="/">
      <span class="toolbox-entry-text">导航</span>
      <i class="icon-angle-down"></i>
      <i class="icon-home"></i>
    </a>
    <ul class="list-toolbox">
      
        <li class="item-toolbox">
          <a
            class="CIRCLE"
            href="/archives/"
            rel="noopener noreferrer"
            target="_self"
            >
            博客
          </a>
        </li>
      
        <li class="item-toolbox">
          <a
            class="CIRCLE"
            href="/categories/"
            rel="noopener noreferrer"
            target="_self"
            >
            分类
          </a>
        </li>
      
        <li class="item-toolbox">
          <a
            class="CIRCLE"
            href="/tags/"
            rel="noopener noreferrer"
            target="_self"
            >
            标签
          </a>
        </li>
      
        <li class="item-toolbox">
          <a
            class="CIRCLE"
            href="/search/"
            rel="noopener noreferrer"
            target="_self"
            >
            搜索
          </a>
        </li>
      
        <li class="item-toolbox">
          <a
            class="CIRCLE"
            href="/link/"
            rel="noopener noreferrer"
            target="_self"
            >
            友链
          </a>
        </li>
      
        <li class="item-toolbox">
          <a
            class="CIRCLE"
            href="/about/"
            rel="noopener noreferrer"
            target="_self"
            >
            关于
          </a>
        </li>
      
    </ul>
  </div>


</div>


  <div id="toc" class="toc-article">
    <strong class="toc-title">文章目录<i class="iconfont toc-title" style="display:inline-block;color:#87998d;width:20px;height:20px;">&#xf004b;</i></strong>
    <ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#一、功能类"><span class="toc-text">一、功能类</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#1-1-html-webpack-plugin"><span class="toc-text">1.1 html-webpack-plugin</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#1-2-copy-webpack-plugin"><span class="toc-text">1.2 copy-webpack-plugin</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#1-3-webpack-manifest-plugin-amp-amp-assets-webpack-plugin"><span class="toc-text">1.3 webpack-manifest-plugin &amp;&amp; assets-webpack-plugin</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#1-4-clean-webpack-plugin"><span class="toc-text">1.4 clean-webpack-plugin</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#1-5-compression-webpack-plugin"><span class="toc-text">1.5 compression-webpack-plugin</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#1-6-progress-bar-webpack-plugin"><span class="toc-text">1.6 progress-bar-webpack-plugin</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#二、代码相关类"><span class="toc-text">二、代码相关类</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#2-1-webpack-ProvidePlugin"><span class="toc-text">2.1 webpack.ProvidePlugin</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#2-2-webpack-DefinePlugin"><span class="toc-text">2.2 webpack.DefinePlugin</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#2-3-mini-css-extract-plugin-amp-amp-extract-text-webpack-plugin"><span class="toc-text">2.3 mini-css-extract-plugin &amp;&amp; extract-text-webpack-plugin</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#三、编译结果优化类"><span class="toc-text">三、编译结果优化类</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#3-1-wbepack-IgnorePlugin"><span class="toc-text">3.1 wbepack.IgnorePlugin</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#3-2-uglifyjs-webpack-plugin"><span class="toc-text">3.2 uglifyjs-webpack-plugin</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#3-3-optimize-css-assets-webpack-plugin"><span class="toc-text">3.3 optimize-css-assets-webpack-plugin</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#3-4-webpack-md5-hash"><span class="toc-text">3.4 webpack-md5-hash</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#3-5-SplitChunksPlugin"><span class="toc-text">3.5 SplitChunksPlugin</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#四、编译优化类"><span class="toc-text">四、编译优化类</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#4-1-DllPlugin-amp-amp-DllReferencePlugin-amp-amp-autodll-webpack-plugin"><span class="toc-text">4.1 DllPlugin &amp;&amp; DllReferencePlugin &amp;&amp; autodll-webpack-plugin</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#4-2-happypack-amp-amp-thread-loader"><span class="toc-text">4.2 happypack &amp;&amp; thread-loader</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#4-3-hard-source-webpack-plugin-amp-amp-cache-loader"><span class="toc-text">4.3 hard-source-webpack-plugin &amp;&amp; cache-loader</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#五、编译分析类"><span class="toc-text">五、编译分析类</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#5-1-webpack-bundle-analyzer"><span class="toc-text">5.1 webpack-bundle-analyzer</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#5-2-stats-webpack-plugin-amp-amp-PrefetchPlugin"><span class="toc-text">5.2 stats-webpack-plugin &amp;&amp; PrefetchPlugin</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#5-3-speed-measure-webpack-plugin"><span class="toc-text">5.3 speed-measure-webpack-plugin</span></a></li></ol></li></ol>
  </div>
  




<div class="content content-post CENTER">
   <!-- canvas 彩带 -->
<canvas id="evanyou" width="1302" height="678" style="position: fixed;width: 100%;height: 100%;top: 0;left:0;z-index:-1;"></canvas>

<article id="post-webpack-config-optize" class="article article-type-post" itemprop="blogPost">
  <header class="article-header" style="position:relative;">
    <h1 class="post-title">webpack常用插件总结篇</h1>

    <div class="article-meta">
      <span>
        <i class="icon-calendar"></i>
        <span>2018.11.21</span>
      </span>

      
        <span class="article-author">
          <i class="icon-user"></i>
          <span>Poetry</span>
        </span>
      

      
  <span class="article-category">
    <i class="icon-list"></i>
    <a class="article-category-link" href="/categories/Front-End/">Front-End</a>
  </span>



      

      
      <i class="fa fa-eye"></i> 
        <span id="busuanzi_container_page_pv">
           &nbsp热度 <span id="busuanzi_value_page_pv">
           <i class="fa fa-spinner fa-spin"></i></span>℃
        </span>
      
      
       
          <span class="post-count">
            <i class="fa fa-file-word-o"></i>&nbsp
            <span>字数统计 1.6k字</span>
          </span>

          <span class="post-count">
            <i class="fa fa-columns"></i>&nbsp
            <span>阅读时长 7分</span>
          </span>
      
      
    </div>

    <i class="iconfont" id="toc-eye" style="display:inline-block;color:#b36619;position:absolute;top:0;right:0;cursor:pointer;
    font-size: 24px;">&#xe61c;</i>

  </header>

  <div class="article-content">
    
      <div id="container">
        <h2 id="一、功能类"><a href="#一、功能类" class="headerlink" title="一、功能类"></a>一、功能类</h2><h3 id="1-1-html-webpack-plugin"><a href="#1-1-html-webpack-plugin" class="headerlink" title="1.1 html-webpack-plugin"></a>1.1 html-webpack-plugin</h3><blockquote>
<p>自动生成<code>html</code>，基本用法：</p>
</blockquote>
<figure class="highlight js"><table><tr><td class="code"><pre><span class="line"><span class="keyword">new</span> HtmlWebpackPlugin(&#123;</span><br><span class="line">  filename: <span class="string">'index.html'</span>, <span class="comment">// 生成文件名</span></span><br><span class="line">  template: path.join(process.cwd(), <span class="string">'./index.html'</span>) <span class="comment">// 模班文件</span></span><br><span class="line">&#125;)</span><br></pre></td></tr></table></figure>
<h3 id="1-2-copy-webpack-plugin"><a href="#1-2-copy-webpack-plugin" class="headerlink" title="1.2 copy-webpack-plugin"></a>1.2 copy-webpack-plugin</h3><blockquote>
<p>拷贝资源插件</p>
</blockquote>
<figure class="highlight js"><table><tr><td class="code"><pre><span class="line"><span class="keyword">new</span> CopyWebpackPlugin([</span><br><span class="line">  &#123;</span><br><span class="line">    <span class="keyword">from</span>: path.join(process.cwd(), <span class="string">'./vendor/'</span>),</span><br><span class="line">    to: path.join(process.cwd(), <span class="string">'./dist/'</span>),</span><br><span class="line">    ignore: [<span class="string">'*.json'</span>]</span><br><span class="line">  &#125;</span><br><span class="line">])</span><br></pre></td></tr></table></figure>
<h3 id="1-3-webpack-manifest-plugin-amp-amp-assets-webpack-plugin"><a href="#1-3-webpack-manifest-plugin-amp-amp-assets-webpack-plugin" class="headerlink" title="1.3 webpack-manifest-plugin &amp;&amp; assets-webpack-plugin"></a>1.3 webpack-manifest-plugin &amp;&amp; assets-webpack-plugin</h3><blockquote>
<p>俩个插件效果一致，都是生成编译结果的资源单，只是资源单的数据结构不一致而已</p>
</blockquote>
<p><strong>webpack-manifest-plugin 基本用法</strong></p>
<figure class="highlight js"><table><tr><td class="code"><pre><span class="line"><span class="built_in">module</span>.exports = &#123;</span><br><span class="line">  plugins: [</span><br><span class="line">    <span class="keyword">new</span> ManifestPlugin()</span><br><span class="line">  ]</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p><strong>assets-webpack-plugin 基本用法</strong></p>
<figure class="highlight js"><table><tr><td class="code"><pre><span class="line"><span class="built_in">module</span>.exports = &#123;</span><br><span class="line">  plugins: [</span><br><span class="line">    <span class="keyword">new</span> AssetsPlugin()</span><br><span class="line">  ]</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h3 id="1-4-clean-webpack-plugin"><a href="#1-4-clean-webpack-plugin" class="headerlink" title="1.4 clean-webpack-plugin"></a>1.4 clean-webpack-plugin</h3><blockquote>
<p>在编译之前清理指定目录指定内容</p>
</blockquote>
<figure class="highlight js"><table><tr><td class="code"><pre><span class="line"><span class="comment">// 清理目录</span></span><br><span class="line"><span class="keyword">const</span> pathsToClean = [</span><br><span class="line">  <span class="string">'dist'</span>,</span><br><span class="line">  <span class="string">'build'</span></span><br><span class="line">]</span><br><span class="line"> </span><br><span class="line"><span class="comment">// 清理参数</span></span><br><span class="line"><span class="keyword">const</span> cleanOptions = &#123;</span><br><span class="line">  exclude:  [<span class="string">'shared.js'</span>], <span class="comment">// 跳过文件</span></span><br><span class="line">&#125;</span><br><span class="line"><span class="built_in">module</span>.exports = &#123;</span><br><span class="line">  <span class="comment">// ...</span></span><br><span class="line">  plugins: [</span><br><span class="line">    <span class="keyword">new</span> CleanWebpackPlugin(pathsToClean, cleanOptions)</span><br><span class="line">  ]</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h3 id="1-5-compression-webpack-plugin"><a href="#1-5-compression-webpack-plugin" class="headerlink" title="1.5 compression-webpack-plugin"></a>1.5 compression-webpack-plugin</h3><blockquote>
<p>提供带 <code>Content-Encoding</code> 编码的压缩版的资源</p>
</blockquote>
<figure class="highlight js"><table><tr><td class="code"><pre><span class="line"><span class="built_in">module</span>.exports = &#123;</span><br><span class="line">  plugins: [</span><br><span class="line">    <span class="keyword">new</span> CompressionPlugin()</span><br><span class="line">  ]</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h3 id="1-6-progress-bar-webpack-plugin"><a href="#1-6-progress-bar-webpack-plugin" class="headerlink" title="1.6 progress-bar-webpack-plugin"></a>1.6 progress-bar-webpack-plugin</h3><blockquote>
<p>编译进度条插件</p>
</blockquote>
<figure class="highlight js"><table><tr><td class="code"><pre><span class="line"><span class="built_in">module</span>.exports = &#123;</span><br><span class="line">  <span class="comment">//...</span></span><br><span class="line">  plugins: [</span><br><span class="line">    <span class="keyword">new</span> ProgressBarPlugin()</span><br><span class="line">  ]</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h2 id="二、代码相关类"><a href="#二、代码相关类" class="headerlink" title="二、代码相关类"></a>二、代码相关类</h2><h3 id="2-1-webpack-ProvidePlugin"><a href="#2-1-webpack-ProvidePlugin" class="headerlink" title="2.1 webpack.ProvidePlugin"></a>2.1 webpack.ProvidePlugin</h3><blockquote>
<p>自动加载模块，如 <code>$</code> 出现，就会自动加载模块；<code>$</code> 默认为<code>&#39;jquery&#39;</code>的<code>exports</code></p>
</blockquote>
<figure class="highlight js"><table><tr><td class="code"><pre><span class="line"><span class="keyword">new</span> webpack.ProvidePlugin(&#123;</span><br><span class="line">  $: <span class="string">'jquery'</span>,</span><br><span class="line">&#125;)</span><br></pre></td></tr></table></figure>
<h3 id="2-2-webpack-DefinePlugin"><a href="#2-2-webpack-DefinePlugin" class="headerlink" title="2.2 webpack.DefinePlugin"></a>2.2 webpack.DefinePlugin</h3><blockquote>
<p>定义全局常量</p>
</blockquote>
<figure class="highlight js"><table><tr><td class="code"><pre><span class="line"><span class="keyword">new</span> webpack.DefinePlugin(&#123;</span><br><span class="line">  <span class="string">'process.env'</span>: &#123;</span><br><span class="line">    NODE_ENV: <span class="built_in">JSON</span>.stringify(process.env.NODE_ENV)</span><br><span class="line">  &#125;</span><br><span class="line">&#125;)</span><br></pre></td></tr></table></figure>
<h3 id="2-3-mini-css-extract-plugin-amp-amp-extract-text-webpack-plugin"><a href="#2-3-mini-css-extract-plugin-amp-amp-extract-text-webpack-plugin" class="headerlink" title="2.3 mini-css-extract-plugin &amp;&amp; extract-text-webpack-plugin"></a>2.3 mini-css-extract-plugin &amp;&amp; extract-text-webpack-plugin</h3><blockquote>
<p>提取css样式，对比</p>
</blockquote>
<ul>
<li><code>mini-css-extract-plugin</code> 为<code>webpack4</code>及以上提供的<code>plugin</code>，支持<code>css chunk</code></li>
<li><code>extract-text-webpack-plugin</code> 只能在<code>webpack3</code> 及一下的版本使用，不支持<code>css chunk</code></li>
</ul>
<p><strong>基本用法 extract-text-webpack-plugin</strong></p>
<figure class="highlight js"><table><tr><td class="code"><pre><span class="line"><span class="keyword">const</span> ExtractTextPlugin = <span class="built_in">require</span>(<span class="string">"extract-text-webpack-plugin"</span>);</span><br><span class="line"> </span><br><span class="line"><span class="built_in">module</span>.exports = &#123;</span><br><span class="line">  <span class="built_in">module</span>: &#123;</span><br><span class="line">    rules: [</span><br><span class="line">      &#123;</span><br><span class="line">        test: <span class="regexp">/\.css$/</span>,</span><br><span class="line">        use: ExtractTextPlugin.extract(&#123;</span><br><span class="line">          fallback: <span class="string">"style-loader"</span>,</span><br><span class="line">          use: <span class="string">"css-loader"</span></span><br><span class="line">        &#125;)</span><br><span class="line">      &#125;</span><br><span class="line">    ]</span><br><span class="line">  &#125;,</span><br><span class="line">  plugins: [</span><br><span class="line">    <span class="keyword">new</span> ExtractTextPlugin(<span class="string">"styles.css"</span>),</span><br><span class="line">  ]</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p><strong>基本用法 mini-css-extract-plugin</strong></p>
<figure class="highlight js"><table><tr><td class="code"><pre><span class="line"><span class="keyword">const</span> MiniCssExtractPlugin = <span class="built_in">require</span>(<span class="string">"mini-css-extract-plugin"</span>);</span><br><span class="line"><span class="built_in">module</span>.exports = &#123;</span><br><span class="line">    <span class="built_in">module</span>: &#123;</span><br><span class="line">    rules: [</span><br><span class="line">      &#123;</span><br><span class="line">        test: <span class="regexp">/\.css$/</span>,</span><br><span class="line">        use: [</span><br><span class="line">          &#123;</span><br><span class="line">            loader: MiniCssExtractPlugin.loader,</span><br><span class="line">            options: &#123;</span><br><span class="line">              publicPath: <span class="string">'/'</span>  <span class="comment">// chunk publicPath</span></span><br><span class="line">            &#125;</span><br><span class="line">          &#125;,</span><br><span class="line">          <span class="string">"css-loader"</span></span><br><span class="line">        ]</span><br><span class="line">      &#125;</span><br><span class="line">    ]</span><br><span class="line">  &#125;,</span><br><span class="line">  plugins: [</span><br><span class="line">    <span class="keyword">new</span> MiniCssExtractPlugin(&#123;</span><br><span class="line">      filename: <span class="string">"[name].css"</span>, <span class="comment">// 主文件名</span></span><br><span class="line">      chunkFilename: <span class="string">"[id].css"</span>  <span class="comment">// chunk文件名</span></span><br><span class="line">    &#125;)</span><br><span class="line">  ]</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h2 id="三、编译结果优化类"><a href="#三、编译结果优化类" class="headerlink" title="三、编译结果优化类"></a>三、编译结果优化类</h2><h3 id="3-1-wbepack-IgnorePlugin"><a href="#3-1-wbepack-IgnorePlugin" class="headerlink" title="3.1 wbepack.IgnorePlugin"></a>3.1 wbepack.IgnorePlugin</h3><blockquote>
<p>忽略<code>regExp</code>匹配的模块</p>
</blockquote>
<figure class="highlight js"><table><tr><td class="code"><pre><span class="line"><span class="keyword">new</span> webpack.IgnorePlugin(<span class="regexp">/^\.\/locale$/</span>, /moment$/)</span><br></pre></td></tr></table></figure>
<h3 id="3-2-uglifyjs-webpack-plugin"><a href="#3-2-uglifyjs-webpack-plugin" class="headerlink" title="3.2 uglifyjs-webpack-plugin"></a>3.2 uglifyjs-webpack-plugin</h3><blockquote>
<p>代码丑化，用于js压缩</p>
</blockquote>
<figure class="highlight js"><table><tr><td class="code"><pre><span class="line"><span class="built_in">module</span>.exports = &#123;</span><br><span class="line">  <span class="comment">//...</span></span><br><span class="line">  optimization: &#123;</span><br><span class="line">    minimizer: [<span class="keyword">new</span> UglifyJsPlugin(&#123;</span><br><span class="line">      cache: <span class="literal">true</span>,   <span class="comment">// 开启缓存</span></span><br><span class="line">      parallel: <span class="literal">true</span>, <span class="comment">// 开启多线程编译</span></span><br><span class="line">      sourceMap: <span class="literal">true</span>,  <span class="comment">// 是否sourceMap</span></span><br><span class="line">      uglifyOptions: &#123;  <span class="comment">// 丑化参数</span></span><br><span class="line">        comments: <span class="literal">false</span>,</span><br><span class="line">        warnings: <span class="literal">false</span>,</span><br><span class="line">        compress: &#123;</span><br><span class="line">          unused: <span class="literal">true</span>,</span><br><span class="line">          dead_code: <span class="literal">true</span>,</span><br><span class="line">          collapse_vars: <span class="literal">true</span>,</span><br><span class="line">          reduce_vars: <span class="literal">true</span></span><br><span class="line">        &#125;,</span><br><span class="line">        output: &#123;</span><br><span class="line">          comments: <span class="literal">false</span></span><br><span class="line">        &#125;</span><br><span class="line">      &#125;</span><br><span class="line">    &#125;]</span><br><span class="line">  &#125;</span><br><span class="line">&#125;;</span><br></pre></td></tr></table></figure>
<h3 id="3-3-optimize-css-assets-webpack-plugin"><a href="#3-3-optimize-css-assets-webpack-plugin" class="headerlink" title="3.3 optimize-css-assets-webpack-plugin"></a>3.3 optimize-css-assets-webpack-plugin</h3><blockquote>
<p>css压缩，主要使用 <code>cssnano</code> 压缩器 <a href="https://github.com/cssnano/cssnano" target="_blank" rel="noopener">https://github.com/cssnano/cssnano</a></p>
</blockquote>
<figure class="highlight js"><table><tr><td class="code"><pre><span class="line"><span class="built_in">module</span>.exports = &#123;</span><br><span class="line">  <span class="comment">//...</span></span><br><span class="line">  optimization: &#123;</span><br><span class="line">    minimizer: [<span class="keyword">new</span> OptimizeCssAssetsPlugin(&#123;</span><br><span class="line">      cssProcessor: <span class="built_in">require</span>(<span class="string">'cssnano'</span>),   <span class="comment">// css 压缩优化器</span></span><br><span class="line">      cssProcessorOptions: &#123; <span class="attr">discardComments</span>: &#123; <span class="attr">removeAll</span>: <span class="literal">true</span> &#125; &#125; <span class="comment">// 去除所有注释</span></span><br><span class="line">    &#125;)]</span><br><span class="line">  &#125;</span><br><span class="line">&#125;;</span><br></pre></td></tr></table></figure>
<h3 id="3-4-webpack-md5-hash"><a href="#3-4-webpack-md5-hash" class="headerlink" title="3.4 webpack-md5-hash"></a>3.4 webpack-md5-hash</h3><blockquote>
<p>使你的<code>chunk</code>根据内容生成<code>md5</code>，用这个<code>md5</code>取代 <code>webpack chunkhash</code>。</p>
</blockquote>
<figure class="highlight js"><table><tr><td class="code"><pre><span class="line"><span class="keyword">var</span> WebpackMd5Hash = <span class="built_in">require</span>(<span class="string">'webpack-md5-hash'</span>);</span><br><span class="line"> </span><br><span class="line"><span class="built_in">module</span>.exports = &#123;</span><br><span class="line">  <span class="comment">// ...</span></span><br><span class="line">  output: &#123;</span><br><span class="line">    <span class="comment">//...</span></span><br><span class="line">    chunkFilename: <span class="string">"[chunkhash].[id].chunk.js"</span></span><br><span class="line">  &#125;,</span><br><span class="line">  plugins: [</span><br><span class="line">    <span class="keyword">new</span> WebpackMd5Hash()</span><br><span class="line">  ]</span><br><span class="line">&#125;;</span><br></pre></td></tr></table></figure>
<h3 id="3-5-SplitChunksPlugin"><a href="#3-5-SplitChunksPlugin" class="headerlink" title="3.5 SplitChunksPlugin"></a>3.5 SplitChunksPlugin</h3><ul>
<li><code>CommonChunkPlugin</code> 的后世，用于<code>chunk</code>切割。</li>
</ul>
<blockquote>
<p><code>webpack</code> 把 <code>chunk</code> 分为两种类型，一种是初始加载<code>initial chunk</code>，另外一种是异步加载 <code>async chunk</code>，如果不配置<code>SplitChunksPlugin</code>，<code>webpack</code>会在<code>production</code>的模式下自动开启，默认情况下，<code>webpack</code>会将 <code>node_modules</code> 下的所有模块定义为异步加载模块，并分析你的 <code>entry</code>、动态加载（<code>import()</code>、<code>require.ensure</code>）模块，找出这些模块之间共用的<code>node_modules</code>下的模块，并将这些模块提取到单独的<code>chunk</code>中，在需要的时候异步加载到页面当中，其中默认配置如下</p>
</blockquote>
<figure class="highlight js"><table><tr><td class="code"><pre><span class="line"><span class="built_in">module</span>.exports = &#123;</span><br><span class="line">  <span class="comment">//...</span></span><br><span class="line">  optimization: &#123;</span><br><span class="line">    splitChunks: &#123;</span><br><span class="line">      chunks: <span class="string">'async'</span>, <span class="comment">// 异步加载chunk</span></span><br><span class="line">      minSize: <span class="number">30000</span>,</span><br><span class="line">      maxSize: <span class="number">0</span>,</span><br><span class="line">      minChunks: <span class="number">1</span>,</span><br><span class="line">      maxAsyncRequests: <span class="number">5</span>,</span><br><span class="line">      maxInitialRequests: <span class="number">3</span>,</span><br><span class="line">      automaticNameDelimiter: <span class="string">'~'</span>, <span class="comment">// 文件名中chunk分隔符</span></span><br><span class="line">      name: <span class="literal">true</span>,</span><br><span class="line">      cacheGroups: &#123;</span><br><span class="line">        vendors: &#123;</span><br><span class="line">          test: <span class="regexp">/[\\/]node_modules[\\/]/</span>,  <span class="comment">// </span></span><br><span class="line">          priority: <span class="number">-10</span></span><br><span class="line">        &#125;,</span><br><span class="line">        <span class="keyword">default</span>: &#123;</span><br><span class="line">          minChunks: <span class="number">2</span>,  <span class="comment">// 最小的共享chunk数</span></span><br><span class="line">          priority: <span class="number">-20</span>,</span><br><span class="line">          reuseExistingChunk: <span class="literal">true</span></span><br><span class="line">        &#125;</span><br><span class="line">      &#125;</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;;</span><br></pre></td></tr></table></figure>
<h2 id="四、编译优化类"><a href="#四、编译优化类" class="headerlink" title="四、编译优化类"></a>四、编译优化类</h2><h3 id="4-1-DllPlugin-amp-amp-DllReferencePlugin-amp-amp-autodll-webpack-plugin"><a href="#4-1-DllPlugin-amp-amp-DllReferencePlugin-amp-amp-autodll-webpack-plugin" class="headerlink" title="4.1 DllPlugin &amp;&amp; DllReferencePlugin &amp;&amp; autodll-webpack-plugin"></a>4.1 DllPlugin &amp;&amp; DllReferencePlugin &amp;&amp; autodll-webpack-plugin</h3><ul>
<li><code>dllPlugin</code>将模块预先编译，<code>DllReferencePlugin</code> 将预先编译好的模块关联到当前编译中，当 <code>webpack</code> 解析到这些模块时，会直接使用预先编译好的模块。</li>
<li><code>autodll-webpack-plugin</code> 相当于 <code>dllPlugin</code> 和 <code>DllReferencePlugin</code> 的简化版，其实本质也是使用 <code>dllPlugin &amp;&amp; DllReferencePlugin</code>，它会在第一次编译的时候将配置好的需要预先编译的模块编译在缓存中，第二次编译的时候，解析到这些模块就直接使用缓存，而不是去编译这些模块</li>
</ul>
<p><strong>dllPlugin 基本用法：</strong></p>
<figure class="highlight js"><table><tr><td class="code"><pre><span class="line"><span class="keyword">const</span> output = &#123;</span><br><span class="line">  filename: <span class="string">'[name].js'</span>,</span><br><span class="line">  library: <span class="string">'[name]_library'</span>,</span><br><span class="line">  path: <span class="string">'./vendor/'</span></span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="built_in">module</span>.exports = &#123;</span><br><span class="line">  entry: &#123;</span><br><span class="line">    vendor: [<span class="string">'react'</span>, <span class="string">'react-dom'</span>]  <span class="comment">// 我们需要事先编译的模块，用entry表示</span></span><br><span class="line">  &#125;,</span><br><span class="line">  output: output,</span><br><span class="line">  plugins: [</span><br><span class="line">    <span class="keyword">new</span> webpack.DllPlugin(&#123;  <span class="comment">// 使用dllPlugin</span></span><br><span class="line">      path: path.join(output.path, <span class="string">`<span class="subst">$&#123;output.filename&#125;</span>.json`</span>),</span><br><span class="line">      name: output.library <span class="comment">// 全局变量名， 也就是 window 下 的 [output.library]</span></span><br><span class="line">    &#125;)</span><br><span class="line">  ]</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p><strong>DllReferencePlugin 基本用法：</strong></p>
<figure class="highlight js"><table><tr><td class="code"><pre><span class="line"><span class="keyword">const</span> manifest = path.resolve(process.cwd(), <span class="string">'vendor'</span>, <span class="string">'vendor.js.json'</span>)</span><br><span class="line"></span><br><span class="line"><span class="built_in">module</span>.exports = &#123;</span><br><span class="line">  plugins: [</span><br><span class="line">    <span class="keyword">new</span> webpack.DllReferencePlugin(&#123;</span><br><span class="line">      manifest: <span class="built_in">require</span>(manifest), <span class="comment">// 引进dllPlugin编译的json文件</span></span><br><span class="line">      name: <span class="string">'vendor_library'</span> <span class="comment">// 全局变量名，与dllPlugin声明的一致</span></span><br><span class="line">    &#125;</span><br><span class="line">  ]</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p><strong>autodll-webpack-plugin 基本用法：</strong></p>
<figure class="highlight js"><table><tr><td class="code"><pre><span class="line"><span class="built_in">module</span>.exports = &#123;</span><br><span class="line">  plugins: [</span><br><span class="line">    <span class="keyword">new</span> AutoDllPlugin(&#123;</span><br><span class="line">      inject: <span class="literal">true</span>, <span class="comment">// 与 html-webpack-plugin 结合使用，注入html中</span></span><br><span class="line">      filename: <span class="string">'[name].js'</span>,</span><br><span class="line">      entry: &#123;</span><br><span class="line">        vendor: [</span><br><span class="line">          <span class="string">'react'</span>,</span><br><span class="line">          <span class="string">'react-dom'</span></span><br><span class="line">        ]</span><br><span class="line">      &#125;</span><br><span class="line">    &#125;)</span><br><span class="line">  ]</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h3 id="4-2-happypack-amp-amp-thread-loader"><a href="#4-2-happypack-amp-amp-thread-loader" class="headerlink" title="4.2 happypack &amp;&amp; thread-loader"></a>4.2 happypack &amp;&amp; thread-loader</h3><blockquote>
<p>多线程编译，加快编译速度，<code>thread-loader</code>不可以和 <code>mini-css-extract-plugin</code> 结合使用</p>
</blockquote>
<p><strong>happypack 基本用法</strong></p>
<figure class="highlight js"><table><tr><td class="code"><pre><span class="line"><span class="keyword">const</span> HappyPack = <span class="built_in">require</span>(<span class="string">'happypack'</span>);</span><br><span class="line"><span class="keyword">const</span> os = <span class="built_in">require</span>(<span class="string">'os'</span>);</span><br><span class="line"><span class="keyword">const</span> happyThreadPool = HappyPack.ThreadPool(&#123; <span class="attr">size</span>: os.cpus().length &#125;);</span><br><span class="line"><span class="keyword">const</span> happyLoaderId = <span class="string">'happypack-for-react-babel-loader'</span>;</span><br><span class="line"></span><br><span class="line"><span class="built_in">module</span>.exports = &#123;</span><br><span class="line">  <span class="built_in">module</span>: &#123;</span><br><span class="line">    rules: [&#123;</span><br><span class="line">      test: <span class="regexp">/\.jsx?$/</span>,</span><br><span class="line">      loader: <span class="string">'happypack/loader'</span>,</span><br><span class="line">      query: &#123;</span><br><span class="line">        id: happyLoaderId</span><br><span class="line">      &#125;,</span><br><span class="line">      include: [path.resolve(process.cwd(), <span class="string">'src'</span>)]</span><br><span class="line">    &#125;]</span><br><span class="line">  &#125;,</span><br><span class="line">  plugins: [<span class="keyword">new</span> HappyPack(&#123;</span><br><span class="line">    id: happyLoaderId,</span><br><span class="line">    threadPool: happyThreadPool,</span><br><span class="line">    loaders: [<span class="string">'babel-loader'</span>]</span><br><span class="line">  &#125;)]</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p><strong>thread-loader 基本用法</strong></p>
<figure class="highlight js"><table><tr><td class="code"><pre><span class="line"><span class="built_in">module</span>.exports = &#123;</span><br><span class="line">  <span class="built_in">module</span>: &#123;</span><br><span class="line">    rules: [</span><br><span class="line">      &#123;</span><br><span class="line">        test: <span class="regexp">/\.js$/</span>,</span><br><span class="line">        include: path.resolve(<span class="string">"src"</span>),</span><br><span class="line">        use: [</span><br><span class="line">          <span class="string">"thread-loader"</span>,</span><br><span class="line">          <span class="comment">// your expensive loader (e.g babel-loader)</span></span><br><span class="line">          <span class="string">"babel-loader"</span></span><br><span class="line">        ]</span><br><span class="line">      &#125;</span><br><span class="line">    ]</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h3 id="4-3-hard-source-webpack-plugin-amp-amp-cache-loader"><a href="#4-3-hard-source-webpack-plugin-amp-amp-cache-loader" class="headerlink" title="4.3 hard-source-webpack-plugin &amp;&amp; cache-loader"></a>4.3 hard-source-webpack-plugin &amp;&amp; cache-loader</h3><blockquote>
<p>使用模块编译缓存，加快编译速度</p>
</blockquote>
<p><strong>hard-source-webpack-plugin 基本用法</strong></p>
<figure class="highlight js"><table><tr><td class="code"><pre><span class="line"><span class="built_in">module</span>.exports = &#123;</span><br><span class="line">  plugins: [</span><br><span class="line">    <span class="keyword">new</span> HardSourceWebpackPlugin()</span><br><span class="line">  ]</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p><strong>cache-loader 基本用法</strong></p>
<figure class="highlight js"><table><tr><td class="code"><pre><span class="line"><span class="built_in">module</span>.exports = &#123;</span><br><span class="line">  <span class="built_in">module</span>: &#123;</span><br><span class="line">    rules: [</span><br><span class="line">      &#123;</span><br><span class="line">        test: <span class="regexp">/\.ext$/</span>,</span><br><span class="line">        use: [</span><br><span class="line">          <span class="string">'cache-loader'</span>,</span><br><span class="line">          ...loaders</span><br><span class="line">        ],</span><br><span class="line">        include: path.resolve(<span class="string">'src'</span>)</span><br><span class="line">      &#125;</span><br><span class="line">    ]</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h2 id="五、编译分析类"><a href="#五、编译分析类" class="headerlink" title="五、编译分析类"></a>五、编译分析类</h2><h3 id="5-1-webpack-bundle-analyzer"><a href="#5-1-webpack-bundle-analyzer" class="headerlink" title="5.1 webpack-bundle-analyzer"></a>5.1 webpack-bundle-analyzer</h3><blockquote>
<p>编译模块分析插件</p>
</blockquote>
<figure class="highlight js"><table><tr><td class="code"><pre><span class="line"><span class="keyword">new</span> BundleAnalyzerPlugin(&#123;</span><br><span class="line">  analyzerMode: <span class="string">'server'</span>,</span><br><span class="line">  analyzerHost: <span class="string">'127.0.0.1'</span>,</span><br><span class="line">  analyzerPort: <span class="number">8889</span>,</span><br><span class="line">  reportFilename: <span class="string">'report.html'</span>,</span><br><span class="line">  defaultSizes: <span class="string">'parsed'</span>,</span><br><span class="line">  generateStatsFile: <span class="literal">false</span>,</span><br><span class="line">  statsFilename: <span class="string">'stats.json'</span>,</span><br><span class="line">  statsOptions: <span class="literal">null</span>,</span><br><span class="line">  logLevel: <span class="string">'info'</span></span><br><span class="line">&#125;),</span><br></pre></td></tr></table></figure>
<h3 id="5-2-stats-webpack-plugin-amp-amp-PrefetchPlugin"><a href="#5-2-stats-webpack-plugin-amp-amp-PrefetchPlugin" class="headerlink" title="5.2 stats-webpack-plugin &amp;&amp; PrefetchPlugin"></a>5.2 stats-webpack-plugin &amp;&amp; PrefetchPlugin</h3><blockquote>
<p><code>stats-webpack-plugin</code> 将构建的统计信息写入文件，该文件可在 <a href="http://webpack.github.io/analyse中上传进行编译分析，并根据分析结果，可使用" target="_blank" rel="noopener">http://webpack.github.io/analyse中上传进行编译分析，并根据分析结果，可使用</a> <code>PrefetchPlugin</code> 对部分模块进行预解析编译</p>
</blockquote>
<p><strong>stats-webpack-plugin 基本用法：</strong></p>
<figure class="highlight js"><table><tr><td class="code"><pre><span class="line"><span class="built_in">module</span>.exports = &#123;</span><br><span class="line">  plugins: [</span><br><span class="line">    <span class="keyword">new</span> StatsPlugin(<span class="string">'stats.json'</span>, &#123;</span><br><span class="line">      chunkModules: <span class="literal">true</span>,</span><br><span class="line">      exclude: [<span class="regexp">/node_modules[\\\/]react/</span>]</span><br><span class="line">    &#125;)</span><br><span class="line">  ]</span><br><span class="line">&#125;;</span><br></pre></td></tr></table></figure>
<p><strong>PrefetchPlugin 基本用法：</strong></p>
<figure class="highlight js"><table><tr><td class="code"><pre><span class="line"><span class="built_in">module</span>.exports = &#123;</span><br><span class="line">  plugins: [</span><br><span class="line">    <span class="keyword">new</span> webpack.PrefetchPlugin(<span class="string">'/web/'</span>, <span class="string">'app/modules/HeaderNav.jsx'</span>),</span><br><span class="line">    <span class="keyword">new</span> webpack.PrefetchPlugin(<span class="string">'/web/'</span>, <span class="string">'app/pages/FrontPage.jsx'</span>)</span><br><span class="line">];</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h3 id="5-3-speed-measure-webpack-plugin"><a href="#5-3-speed-measure-webpack-plugin" class="headerlink" title="5.3 speed-measure-webpack-plugin"></a>5.3 speed-measure-webpack-plugin</h3><blockquote>
<p>统计编译过程中，各<code>loader</code>和<code>plugin</code>使用的时间</p>
</blockquote>
<figure class="highlight js"><table><tr><td class="code"><pre><span class="line"><span class="keyword">const</span> SpeedMeasurePlugin = <span class="built_in">require</span>(<span class="string">"speed-measure-webpack-plugin"</span>);</span><br><span class="line"> </span><br><span class="line"><span class="keyword">const</span> smp = <span class="keyword">new</span> SpeedMeasurePlugin();</span><br><span class="line"> </span><br><span class="line"><span class="keyword">const</span> webpackConfig = &#123;</span><br><span class="line">  plugins: [</span><br><span class="line">    <span class="keyword">new</span> MyPlugin(),</span><br><span class="line">    <span class="keyword">new</span> MyOtherPlugin()</span><br><span class="line">  ]</span><br><span class="line">&#125;</span><br><span class="line"><span class="built_in">module</span>.exports = smp.wrap(webpackConfig);</span><br></pre></td></tr></table></figure>
<p><img src="https://segmentfault.com/img/remote/1460000016816816?w=400&amp;h=421" alt></p>

      </div>
    
  </div>

</article>

<button class="assist-btn2 circle" id="assist_btn2" title="点亮屏幕" style="left: 27px; top: 152px;">
  <i class="iconfont" style="display:inline-block;color:red;width:20px;height:20px;">&#xe61d;</i>
</button>
<button class="assist-btn1 circle" id="assist_btn1" title="关闭屏幕亮度" style="left: 27px; top: 152px;">
  <i class="iconfont toc-title" style="display:inline-block;color:red;width:20px;height:20px;">&#xe61d;</i>
</button>


<script src="//cdn.bootcss.com/jquery/3.1.1/jquery.min.js"></script>	

<script src="https://my.openwrite.cn/js/readmore.js" type="text/javascript"></script>
<script>
  const btw = new BTWPlugin();
  btw.init({
    id: "container",
    blogId: "22699-1592137983091-414",
    name: "前端进阶之旅",
    qrcode: "https://poetries1.gitee.io/img-repo/2020/06/qrcode.jpg",
    keyword: "3a3b3c",
  });
</script>

<script type="text/javascript">

// white theme
var body = {color: "#555", background: "#000"};
var a_tag = {color: "#222"};
var header = { background: "#222"};
var logo_line_i = {background: "#222"};
// var post_code = {background: "#eee", color: "#222"};

function switch_theme() {
 $("body").css(body);
 $("a:not('.links-of-author-item a, .site-state-item a, .site-state-posts a, .feed-link a, .motion-element a, .post-tags a, .show-commit-cls a, #donate_board a')").css(a_tag);
 $(".header, .footer").css(header);
 $(".logo-line-before i, .logo-line-after i").css(logo_line_i);
 //$(".post code").css(post_code);
 $("#idhyt-surprise-ball #idhyt-surprise-ball-animation .drag").css(a_tag);
 $(".post-title-link, .posts-expand .post-meta, .post-comments-count, .disqus-comment-count, .post-category a, .post-nav-next a, .post-nav-item a").css(a_tag);
 
 // $("code").css({color: '#c5c8c6', background: '#1d1f21'});
 //$("#assist_btn1").hide(1500);
}

$(function () {
$("#assist_btn2").css("display","none");
 $("#assist_btn1").click(function() {
     switch_theme();
$("div#toc.toc-article").css({
 "background":"#eaeaea",
 "opacity":1
});
$(".toc-article ol").show();
$("#toc.toc-article .toc-title").css("color","#a98602");
$("#assist_btn1").css("display","none");
$("#assist_btn2").css("display","block");
 });
$("#assist_btn2").click(function() {
$("#assist_btn2").css("display","none");
$("#assist_btn1").css("display","block");
$("body").css("background","url(http://www.miaov.com/static/ie/images/news/bg.png)")
     $(".header, .footer").css("background","url(http://www.miaov.com/static/ie/images/news/bg.png)")
$(".toc-article ol").toggle(1000);
 });
});


//背景随机

var Y, O, E, L, B, C, T, z, N, S, A, I;
!function() {
var e = function() {
for (O.clearRect(0, 0, L, B), T = [{
x: 0,
y: .7 * B + C
}, {
x: 0,
y: .7 * B - C
}]; T[1].x < L + C;) t(T[0], T[1])
}, t = function(e, t) {
O.beginPath(), O.moveTo(e.x, e.y), O.lineTo(t.x, t.y);
var n = t.x + (2 * I() - .25) * C,
 r = a(t.y);
O.lineTo(n, r), O.closePath(), N -= S / -50, O.fillStyle = "#" + (127 * A(N) + 128 << 16 | 127 * A(N + S / 3) + 128 << 8 | 127 * A(N + S / 3 * 2) + 128).toString(16), O.fill(), T[0] = T[1], T[1] = {
 x: n,
 y: r
}
}, a = function n(e) {
var t = e + (2 * I() - 1.1) * C;
return t > B || t < 0 ? n(e) : t
};
Y = document.getElementById("evanyou"), O = Y.getContext("2d"), E = window.devicePixelRatio || 1, L = window.innerWidth, B = window.innerHeight, C = 90, z = Math, N = 0, S = 2 * z.PI, A = z.cos, I = z.random, Y.width = L * E, Y.height = B * E, O.scale(E, E), O.globalAlpha = .6, document.onclick = e, document.ontouchstart = e, e()
}()

   
$("#toc-eye").click(function(){
$("#toc.toc-article").toggle(1000);
});

</script>


   
  <div class="text-center donation">
    <div class="inner-donation">
      <span class="btn-donation">支持一下</span>
      <div class="donation-body">
        <div class="tip text-center">扫一扫，支持poetries</div>
        <ul>
        
          <li class="item">
            
              <span>微信扫一扫</span>
            
            <img src="/images/weixin.jpg" alt="">
          </li>
        
          <li class="item">
            
              <span>支付宝扫一扫</span>
            
            <img src="/images/zhifubao.jpg" alt="">
          </li>
        
        </ul>
      </div>
    </div>
  </div>


   
  <div class="box-prev-next clearfix">
    <a class="show pull-left" href="/2018/11/20/performance-fps/">
        <i class="icon icon-angle-left"></i>
    </a>
    <a class="show pull-right" href="/2018/11/21/webpack-review/">
        <i class="icon icon-angle-right"></i>
    </a>
  </div>




</div>


  <a id="backTop" class="back-top">
    <i class="icon-angle-up"></i>
  </a>




  <div class="modal" id="modal">
  <span id="cover" class="cover hide"></span>
  <div id="modal-dialog" class="modal-dialog hide-dialog">
    <div class="modal-header">
      <span id="close" class="btn-close">关闭</span>
    </div>
    <hr>
    <div class="modal-body">
      <ul class="list-toolbox">
        
          <li class="item-toolbox">
            <a
              class="CIRCLE"
              href="/archives/"
              rel="noopener noreferrer"
              target="_self"
              >
              博客
            </a>
          </li>
        
          <li class="item-toolbox">
            <a
              class="CIRCLE"
              href="/categories/"
              rel="noopener noreferrer"
              target="_self"
              >
              分类
            </a>
          </li>
        
          <li class="item-toolbox">
            <a
              class="CIRCLE"
              href="/tags/"
              rel="noopener noreferrer"
              target="_self"
              >
              标签
            </a>
          </li>
        
          <li class="item-toolbox">
            <a
              class="CIRCLE"
              href="/search/"
              rel="noopener noreferrer"
              target="_self"
              >
              搜索
            </a>
          </li>
        
          <li class="item-toolbox">
            <a
              class="CIRCLE"
              href="/link/"
              rel="noopener noreferrer"
              target="_self"
              >
              友链
            </a>
          </li>
        
          <li class="item-toolbox">
            <a
              class="CIRCLE"
              href="/about/"
              rel="noopener noreferrer"
              target="_self"
              >
              关于
            </a>
          </li>
        
      </ul>

    </div>
  </div>
</div>



  
      <div class="fexo-comments comments-post">
    

    

    
    

    

    
    

    

<!-- Gitalk评论插件通用代码 -->
<div id="gitalk-container"></div>

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/gitalk@1/dist/gitalk.css">
<script src="https://cdn.jsdelivr.net/npm/gitalk@1/dist/gitalk.min.js"></script>
<script>
const gitalk = new Gitalk({
  clientID: '5567a2c4abb858009d96',
  clientSecret: 'b9039ec056cf5c2346b3cdb63308a28c163f91e5',
  repo: 'poetries.github.io',
  owner: 'poetries',
  // 在这里设置一下截取前50个字符串, 这是因为 github 对 label 的长度有了要求, 如果超过
  // 50个字符串则会报错.
  // id: location.pathname.split('/').pop().substring(0, 49),
  id: location.pathname,
  admin: ['poetries'],
  // facebook-like distraction free mode
  distractionFreeMode: false
})
gitalk.render('gitalk-container')
</script>
<!-- Gitalk代码结束 -->



  </div>

  

  <script type="text/javascript">
  function loadScript(url, callback) {
    var script = document.createElement('script')
    script.type = 'text/javascript';

    if (script.readyState) { //IE
      script.onreadystatechange = function() {
        if (script.readyState == 'loaded' ||
          script.readyState == 'complete') {
          script.onreadystatechange = null;
          callback();
        }
      };
    } else { //Others
      script.onload = function() {
        callback();
      };
    }

    script.src = url;
    document.getElementsByTagName('head')[0].appendChild(script);
  }

  window.onload = function() {
    loadScript('/js/bundle.js?235683', function() {
      // load success
    });
  }
</script>


  <!-- 页面点击小红心 -->
  <script type="text/javascript" src="/js/clicklove.js"></script>
 
  
</body>
</html>
